import { FeatureManager } from '@amcax/base';
import {
  CmdButton,
  CmdSplitButton,
  CmdTabItem,
  CmdTabs,
} from '@app-cad/components/CommandBar';

import { nmAppLog } from '../../common/utils';

// Mesh CMD
import {
  cmdAutoMesh,
  cmdDistribution,
  cmdElement,
  cmdMeshSize,
  cmdNode,
  cmdReferPoint,
  cmdSurface,
} from '../../commands/mesh';

// Tools CMD
import { cmdMeshQuality } from '../../commands/tools/cmd-mesh-quality';

// Draw CMD
import {
  cmdCloudPicture,
  cmdDeformation,
  cmdIsosurface,
  cmdTensor,
  cmdVectorGraph,
} from '../../commands/draw';

// Component

export default function CommandBar() {
  const onTabSwitch = async (itemId: string) => {
    nmAppLog('CommandBar2 onTabSwitch', { itemId });
  };

  const tabItems: CmdTabItem[] = [
    {
      id: 'mesh',
      label: '网格',
      children: (
        <>
          {FeatureManager.isFeatureEnabled('cmd-mesh-control') && (
            <>
              <CmdButton cmd={cmdMeshSize} />
              <CmdButton cmd={cmdDistribution} />
              <CmdButton cmd={cmdAutoMesh} />
            </>
          )}
          {FeatureManager.isFeatureEnabled('cmd-collection') && (
            <CmdSplitButton
              key='cmd-collection'
              cmds={[cmdNode, cmdElement, cmdSurface, cmdReferPoint]}
            />
          )}
        </>
      ),
    },
    {
      id: 'tools',
      label: '工具',
      children: (
        <>
          {FeatureManager.isFeatureEnabled('cmd-mesh-quality') && (
            <CmdButton cmd={cmdMeshQuality} />
          )}
        </>
      ),
    },
    {
      id: 'draw',
      label: '结果',
      children: (
        <>
          {FeatureManager.isFeatureEnabled('cmd-vector-graph') && (
            <CmdButton cmd={cmdVectorGraph} />
          )}
          {FeatureManager.isFeatureEnabled('cmd-cloud-picture') && (
            <CmdButton cmd={cmdCloudPicture} />
          )}
          {FeatureManager.isFeatureEnabled('cmd-tensor') && (
            <CmdButton cmd={cmdTensor} />
          )}

          {FeatureManager.isFeatureEnabled('cmd-deformation') && (
            <CmdButton cmd={cmdDeformation} />
          )}
          {FeatureManager.isFeatureEnabled('cmd-isosurface') && (
            <CmdButton cmd={cmdIsosurface} />
          )}
        </>
      ),
    },
  ].filter((item) => item !== undefined);
  return (
    <CmdTabs
      items={tabItems}
      frozenIds={['mesh', 'tools', 'draw']}
      onTabSwitch={onTabSwitch}
    />
  );
}
